#define  _CRT_SECURE_NO_WARNINGS
class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int num_zero = 0;
        int left = 0, right = 0, n = nums.size(), ret = 0;
        while (right < n)
        {
            if (!nums[right])num_zero++;
            while (num_zero > k)
            {
                if (!nums[left++])num_zero--;
            }
            ret = max(ret, right - left + 1);
            right++;
        }
        return ret;
    }
};